<?php

header('Access-Control-Allow-Origin: *');
include('../_inc/config.inc.php');

$_latitude_center = $_GET['latitude_center'];
$_longitude_center = $_GET['longitude_center'];
$_latitude_south_west = $_GET['latitude_south_west'];
$_longitude_south_west = $_GET['longitude_south_west'];
$_latitude_north_est = $_GET['latitude_north_est'];
$_longitude_north_est = $_GET['longitude_north_est'];

$data = array();
$data['error_code'] = 0;
$data['error_desc'] = '';
$data['result'] = array();

if( empty($_latitude_south_west) || empty($_longitude_south_west) || empty($_latitude_north_est) || empty($_longitude_north_est)){
	    $data['error_code'] = 2;
		$data['error_desc'] = 'Paramètre manquant';
		echo json_encode($data);
		exit();
}

// Exécution de la requête
$query = 'SELECT * from POI 
			WHERE poi_latitude >= '.$_latitude_south_west.' 
			AND poi_latitude <= '.$_latitude_north_est.'
			AND poi_longitude >= '.$_longitude_south_west.'
			AND poi_longitude <= '.$_longitude_north_est;
			//echo $query;
$result = mysql_query($query);


// Vérification du résultat
if (!$result) {
    $data['error_code'] = 1;
	$data['error_desc'] = 'Erreur sur la requête';
	echo json_encode($data);
	exit();
}

// Utilisation du résultat
while ($row = mysql_fetch_assoc($result)) {
    $data['result'][] = $row;
}

echo json_encode($data);
/*
if (isset($_GET['callback'])) echo $_GET['callback'].'('.$data.');'; 
else echo $data;*/